package crp.services.api.graphql.models;

import com.qwlabs.lang.F2;
import crp.core.course.domain.models.CourseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Ignore;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;

@Type("Course")
@Builder
@Getter
@AllArgsConstructor
public class CoursePayload {
    @Id
    @NotNull
    private final String id;
    @NotNull
    private final String code;
    @NotNull
    private final String name;
    @Ignore
    private final String planCourseId;

    public static CoursePayload of(CourseEntity entity) {
        return F2.ifPresent(entity, () ->
                CoursePayload.builder()
                        .id(entity.getId())
                        .code(entity.getCode())
                        .name(entity.getName())
                        .planCourseId(entity.getPlanCourse().getId())
                        .build());
    }
}
